<!DOCTYPE html>
<html>

<head>
    <title>比赛结束 - 答题系统</title>
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.2.1/css/all.min.css">
    <link href="/css/leaderboard.css" rel="stylesheet">
    <style>
        /* 顶部导航栏样式 */
        .top-nav {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: 64px;
            background: rgba(0, 0, 0, 0.2);
            backdrop-filter: blur(10px);
            display: flex;
            align-items: center;
            padding: 0 2rem;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            z-index: 100;
        }

        .nav-title {
            color: white;
            font-size: 1.25rem;
            font-weight: 500;
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .nav-title i {
            font-size: 1.2rem;
            color: rgba(255, 255, 255, 0.9);
        }

        .nav-title span {
            font-size: 1.5rem;
            font-weight: bold;
        }

        .container {
            padding: 6rem 1.5rem 2rem;
        }

        .result-card {
            background: var(--surface);
            border-radius: 1rem;
            width: 100%;
            margin: 0 auto;
            height: 85vh;
            box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
            display: flex;
            flex-direction: column;
        }

        .leaderboard {
            padding: 2rem;
            flex: 1;
            overflow-y: auto;
        }

        :root {
            --primary-color: #2196F3;
            --secondary-color: #1976D2;
            --accent-color: #FF4081;
            --background: #f8f9fa;
            --surface: #ffffff;
            --text-primary: #212121;
            --text-secondary: #757575;
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        html,
        body {
            height: 100%;
            margin: 0;
            font-family: 'Roboto', sans-serif;
            background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
            overflow: hidden;
        }

        .main-content {
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        @media (max-width: 768px) {
            .container {
                padding: 6rem 1rem 2rem;
                /* 调整左右间隔 */
            }

            .leaderboard {
                padding: 1rem;
                /* 保持一致的间隔 */
            }
        }
    </style>
    <script src="/basic.js"></script>
    <script src="/js/leaderboard.js"></script>
</head>

<body>
    <nav class="top-nav">
        <div class="nav-title">
            <i id="backButton" class="fas fa-angle-left"></i>
            <span id="navQuizTitle"></span> 结束页面
        </div>
    </nav>

    <div class="container">
        <div class="main-content">
            <div class="result-card">
                <ul class="leaderboard" id="leaderboard">
                    <!-- 动态生成内容 -->
                </ul>
            </div>
        </div>
    </div>

    <script>
        const urlParams = new URLSearchParams(window.location.search);
        const quizId = urlParams.get('id');

        async function loadQuizInfo() {
            try {
                const response = await fetch(`/quiz/${quizId}`);
                const { data } = await response.json();
                document.getElementById('navQuizTitle').textContent = data.name;
                document.title = data.name;
            } catch (error) {
                console.error('加载失败:', error);
            }
        }

        document.addEventListener('DOMContentLoaded', () => {
            loadQuizInfo();
            loadLeaderboard(`/quiz/${quizId}/quiz_rank`);
        });

        document.getElementById('backButton').addEventListener('click', () => {
            if (window.innerWidth <= 768) {
                window.location.href = '/list_mobile';
            } else {
                window.location.href = '/list';
            }
        });
    </script>
</body>

</html>